ReplaceChar Function

public function ReplaceChar(string, char, rep) result(outstring)

char is replaced with rep

Arguments

Type IntentOptional Attributes Name
character(len=*) :: string
character(len=1) :: char
character(len=1) :: rep

Return Value character(len=LEN(string))


Variables

Type Visibility Attributes Name Initial
integer, public :: i

Source Code

FUNCTION ReplaceChar &
!
(string, char, rep) &
!
RESULT (outstring)

IMPLICIT NONE

!arguments with intent(in):
CHARACTER(*)        :: string
CHARACTER (LEN = 1) :: char, rep

!local declarations
CHARACTER(LEN(string)) :: outstring  
INTEGER             :: i

!------------end of declaration------------------------------------------------

outstring = string

DO
   i = INDEX(outstring,char) 
   IF (i == 0) EXIT
   outstring = outstring(:i-1) // rep // outstring(i+1:)
END DO

RETURN
END FUNCTION ReplaceChar